using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeObject : MonoBehaviour
{
    public GameObject destoryEffect;
    public GameObject[] reward;
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "PlayerBullet")
        {
            //销毁时概率创建道具
            int range = Random.Range(0, 100);
            if (range < 50 && reward.Length != 0)
            {
                Instantiate(reward[Random.Range(0, reward.Length)], transform.position, transform.rotation);
            }
            LifeCycle();
        }
    }
    public void LifeCycle()
    {
        if (destoryEffect != null)
        {
            //播放特效
            GameObject eff =
            Instantiate(destoryEffect, transform.position, transform.rotation);
            //控制特效声音
            AudioSource audio = eff.GetComponent<AudioSource>();
            if (audio != null)
            {
                audio.mute = !GameDataMgr.Instance.soundData.isOnSoundEffect;
                audio.volume = GameDataMgr.Instance.soundData.soundEffectValue;
                Destroy(gameObject);
            }
            else
            {
                Debug.Log(gameObject.name + "的audio为空");
            }
        }
        else
        {
            Debug.Log(gameObject.name + "的destoryEffect为空");
        }
    }
}
